package cn.aib.eduservice.controller.front;

import cn.aib.commonutils.R;
import cn.aib.eduservice.entity.EduCourse;
import cn.aib.eduservice.entity.EduTeacher;
import cn.aib.eduservice.service.EduCourseService;
import cn.aib.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice/indexfront")
//@CrossOrigin
public class IndexController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService eduCourseService;

    /**
     *  查询讲师和课程记录
     *  方法名：selectTeachersAndCourses
     *  参数：查询记录数
     *  返回值：R
     */
    @GetMapping("/index")
    public R selectTeachersAndCourses(){
        //查询讲师
        QueryWrapper<EduTeacher> teacherWrapper = new QueryWrapper<>();

        teacherWrapper.orderByDesc("id");
        teacherWrapper.last("limit 4");

        List<EduTeacher> teacherList = teacherService.selectTeacherlist(teacherWrapper);

        //查询课程
        QueryWrapper<EduCourse> courseWrapper = new QueryWrapper<>();

        courseWrapper.orderByDesc("id");
        courseWrapper.last("limit 8");

        List<EduCourse> courseList = eduCourseService.selectCourselist(courseWrapper);

        return R.ok().data("teacherList",teacherList).data("courseList",courseList);
    }
}
